package me.miencraft.plugin.superlobby.item;

import lombok.Getter;
import me.miencraft.plugin.superlobby.util.CommandEntry;
import me.miencraft.plugin.superlobby.util.CommandType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 加入游戏时给予玩家的物品
 * @author langle__
 * @version 1.0
 */
@Getter
public class JoinItem extends CustomItem {
    
    private final int slot;
    private final List<CommandEntry> commandList;

    public JoinItem(@NotNull ItemProperties properties, int slot, @NotNull List<String> commandList) {
        super(properties);
        this.slot = slot;
        this.commandList = CommandEntry.parseCommands(commandList);
    }

    @Override
    public void onItemUse(Player player) {
        for (CommandEntry entry : commandList) {
            entry.execute(player);
        }
    }

    /**
     * 将物品设置到玩家指定槽位
     * @param player 玩家
     */
    public void giveItemToPlayer(Player player) {
        player.getInventory().setItem(slot, toItemStack());
    }

}
